//
//  ygmJZCJLCFHomeMsgListControllerEVhAUy.m
//  Dvjf_ios
//
//  Created by Ji on 2018/9/11.
//  Copyright © 2018年 ski. All rights reserved.
//

#import "ygmJZCJLCFHomeMsgListControllerEVhAUy.h"
#import "IpxzlFJLCFHomeRequestPfjhYJ.h"
#import "oXlSXWJLCFHomeMsgCenterResultModeluMXJKS.h"
#import "ozWbrEJLCFHomeMsgListCelluoRRlA.h"

@interface ygmJZCJLCFHomeMsgListControllerEVhAUy () {
    NSInteger _pageNumber;
}

@property (nonatomic, strong) oXlSXWJLCFHomeMsgCenterResultModeluMXJKS *TgzwxAresultModelZWmmrE;
@property (nonatomic, strong) NSMutableArray *msgArr;

@end

@implementation ygmJZCJLCFHomeMsgListControllerEVhAUy

- (NSMutableArray *)msgArr {
    if (!_msgArr) {
        _msgArr = [NSMutableArray array];
    }
    return _msgArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self addNavigationBar];
    self.navigationBar.title = self.title;
    self.view.backgroundColor = QTZ_Gray237;
    [self loadData];
}

- (void)loadData {
    
    [self.msgArr removeAllObjects];
    _pageNumber = 1;
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setSafeObject:@(_pageNumber) forKey:@"page"];
    [params setSafeObject:self.zfNWacmsgCodeFdzEVY forKey:@"msgCode"];
    
    [IpxzlFJLCFHomeRequestPfjhYJ msgCenterDataWithParams:params loadingInView:self.view success:^(oXlSXWJLCFHomeMsgCenterResultModeluMXJKS *home) {
        
        [self hideNoMoreDataNotice];
        if (home.data.count > 0) {
            [self.msgArr addObjectsFromArray:home.data];
        } else {
            self.tableView.tableHeaderView = nil;
            [self showNoMoreDataNotice:@"没有更多了"];
        }
        [self.tableView reloadData];
        [self endRefresh];
        
    } failure:^(NSString *error) {
        [self showNotice:error];
        [self endRefresh];
    }];
    
}

- (void)loadMoreData {
    _pageNumber ++;
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setSafeObject:@(_pageNumber) forKey:@"page"];
    [params setSafeObject:self.zfNWacmsgCodeFdzEVY forKey:@"msgCode"];
    
    [IpxzlFJLCFHomeRequestPfjhYJ msgCenterDataWithParams:params loadingInView:self.view success:^(oXlSXWJLCFHomeMsgCenterResultModeluMXJKS *home) {
        
        if (home.data.count > 0) {
            
            [self.msgArr addObjectsFromArray:home.data];
        } else {
            self.tableView.mj_footer.hidden = YES;
            [self showNoMoreDataNotice:@"没有更多了"];
        }
        [self.tableView reloadData];
        [self endLoadMore];
        
    } failure:^(NSString *error) {
        [self showNotice:error];
        [self endRefresh];
    }];
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *rRHNlxheaderViewfJQeRl = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, 10)];
    rRHNlxheaderViewfJQeRl.backgroundColor = [UIColor clearColor];
    return rRHNlxheaderViewfJQeRl;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.msgArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [HomeMsgListCell heightForCellWithDes:((fqVkpZJLCFHomeMsgCenterDataModellnIabV *)[self.msgArr safeObjectAtIndex:indexPath.section]).msg];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HomeMsgListCell *cell = [HomeMsgListCell dequeueReusableCellForTableView:tableView];
    cell.data = [self.msgArr safeObjectAtIndex:indexPath.section];
    [cell reloadData];
    return cell;
}


@end
